package com.hyl;

import com.hyl.creature.*;
import com.hyl.monsterInEachCave.EntranceMonsterSet;
import com.hyl.monsterInEachCave.MiddleCaveMonsterSet;
import com.hyl.monsterInEachCave.RattanCaveCreatureSet;
import com.hyl.monsterInEachCave.WolfCaveMonsterSet;
import com.hyl.weapon.*;

import java.util.Scanner;

/**
 * @description:
 * @author: molar
 * @date: Created in 2020/6/14 12:05
 * @version:
 * @modified By:
 */
public class Sense {
    private PersonPlayer player = new PersonPlayer();
    private PersonBabys babys = new PersonBabys();
    private MonsterWolf wolf1 = new MonsterWolf();
    private MonsterWolf wolf2 = new MonsterWolf();
    private MonsterBird bird1 = new MonsterBird();
    private MonsterBird bird2 = new MonsterBird();
    private MonsterMonkey monkey = new MonsterMonkey();
    private MonsterRattan rattan = new MonsterRattan();
    private Cave currentCave = new Cave();
    private CaveSet caveSet = new CaveSet();
    private EntranceMonsterSet entranceMonsterSet = new EntranceMonsterSet();
    private MiddleCaveMonsterSet middleCaveMonsterSet = new MiddleCaveMonsterSet();
    private RattanCaveCreatureSet rattanCaveMonsterSet = new RattanCaveCreatureSet();
    private WolfCaveMonsterSet wolfCaveMonsterSet = new WolfCaveMonsterSet();
    private int temp;


    Ui ui = new Ui();
    Scanner scanner = new Scanner(System.in);

    public void initSense() {
        initPerson();
        initMonster();
        initCave();
    }

    public void initPerson() {
        player.setId("20202020");
        player.setDescription("林生");
        player.setHPValue(400);
        player.setCurrentWeapon(new AttackWeaponBlackChess("BChess", "黑棋子", -50));

        babys.setHPValue(50);

    }

    public void initMonster() {
        wolf1.setId("wolf1");
        wolf1.setDescription("疾风狼01号");
        wolf1.setHPValue(150);
        wolf1.setCurrentWeapon(new AttackWeaponClaw("w1", "狼爪1", -40));


        wolf2.setId("wolf2");
        wolf2.setDescription("疾风狼02号");
        wolf2.setHPValue(150);
        wolf2.setCurrentWeapon(new AttackWeaponClaw("w2", "狼爪2", -50));

        bird1.setId("bird1");
        bird1.setDescription("啼哭鸟01号");
        bird1.setHPValue(100);
        bird1.setCurrentWeapon(new AttackWeaponVoice("v1", "音波嗓1", -40));


        bird2.setId("bird2");
        bird2.setDescription("啼哭鸟");
        bird2.setHPValue(100);
        bird2.setCurrentWeapon(new AttackWeaponVoice("v2", "音波嗓2", -40));


        monkey.setId("monkey1");
        monkey.setDescription("千面猴");
        monkey.setHPValue(200);
        monkey.setCurrentWeapon(new AttackWeaponClaw("m1", "猴爪", -30));


        rattan.setId("Boss");
        rattan.setDescription("吸血藤");
        rattan.setHPValue(400);
        rattan.setCurrentWeapon(new AttackWeaponRattan("r1", "藤鞭", -40));


        entranceMonsterSet.getEntranceMonsters().add(monkey);
        entranceMonsterSet.getEntranceMonsters().add(bird1);

        middleCaveMonsterSet.getMiddleMonsters().add(wolf1);
        middleCaveMonsterSet.getMiddleMonsters().add(bird2);

        wolfCaveMonsterSet.getWolfCaveMonsters().add(wolf2);

        rattanCaveMonsterSet.getRattanCaveCreatures().add(rattan);
        rattanCaveMonsterSet.getRattanCaveCreatures().add(babys);
    }

    public void initCave() {
        Cave entrance, MiddleCave, WolfCave, rattanCave, cureLampCave, emptyCave;
        entrance = new Cave("01", "入口");
        MiddleCave = new Cave("02", "中间洞");
        WolfCave = new Cave("03", "狼洞");
        rattanCave = new Cave("04", "吸血藤洞");
        cureLampCave = new Cave("05", "治愈灯洞");
        emptyCave = new Cave("06", "空穴");

        entrance.setExits(WolfCave, MiddleCave, emptyCave, null);
        MiddleCave.setExits(null, rattanCave, cureLampCave, entrance);
        WolfCave.setExits(null, rattanCave, null, entrance);
        rattanCave.setExits(WolfCave, null, cureLampCave, MiddleCave);
        cureLampCave.setExits(null, rattanCave, null, MiddleCave);
        emptyCave.setExits(null, null, null, entrance);

        caveSet.getCaves().add(entrance);
        caveSet.getCaves().add(MiddleCave);
        caveSet.getCaves().add(WolfCave);
        caveSet.getCaves().add(rattanCave);
        caveSet.getCaves().add(cureLampCave);
        caveSet.getCaves().add(emptyCave);

        currentCave = entrance;

    }

    public void goCave(String caveId) {
        Cave nextCave = null;
        if (caveId.equals(currentCave.getEastExit().getId())) {
            nextCave = currentCave.getEastExit();
        }
        if (caveId.equals(currentCave.getSouthExit().getId())) {
            nextCave = currentCave.getSouthExit();
        }
        if (caveId.equals(currentCave.getWestExit().getId())) {
            nextCave = currentCave.getWestExit();
        }
        if (caveId.equals(currentCave.getNorthExit().getId())) {
            nextCave = currentCave.getNorthExit();
        }

        if (nextCave == null) {
            System.out.println("那里没有门！");
        } else {
            currentCave = nextCave;
        }
    }

    public void play() {
        ui.displayBackground();
        ui.displayWelcome();
        while (true) {
            ui.displayStaus(this, currentCave.getId());
            ui.displayPlace(currentCave);
            ui.displayThen(this, currentCave.getId());

            String command = scanner.nextLine();
            String[] cmddLineItem = command.split(" ");

            if (currentCave.getId().equals("01")) {

                if (cmddLineItem[0].equals("bye")) {
                    ui.displayBye();
                    System.exit(0);
                } else if (cmddLineItem[0].equals("help")) {
                    ui.displayHelpMsg();
                } else if (cmddLineItem[0].equals("go")) {
                    goCave(cmddLineItem[1]);

                } else if (cmddLineItem[0].equals("attack")) {
                    this.temp = temp+1;
                    this.getPlayer().UseSingleFunctionWeapon(this.getPlayer().getCurrentWeapon(), this.getEntranceMonsterSet().getEntranceMonster(cmddLineItem[1]));

                    for (Monster item:this.getEntranceMonsterSet().getEntranceMonsters()){
                        if (1==Utils.randomMonsterChop(0,2)){
                            item.UseSingleFunctionWeapon(item.getCurrentWeapon(), this.getPlayer());
                        }else {

                        }
                    }

                } else {
                    ui.displyErrorCmdMsg();
                }
            }
            if (currentCave.getId().equals("02")) {

                if (cmddLineItem[0].equals("bye")) {
                    ui.displayBye();
                    System.exit(0);
                } else if (cmddLineItem[0].equals("help")) {
                    ui.displayHelpMsg();
                } else if (cmddLineItem[0].equals("go")) {
                    goCave(cmddLineItem[1]);
                } else if (cmddLineItem[0].equals("attack")) {
                    this.getPlayer().UseSingleFunctionWeapon(this.getPlayer().getCurrentWeapon(), this.getEntranceMonsterSet().getEntranceMonster(cmddLineItem[1]));

                    for (Monster item:this.getMiddleCaveMonsterSet().getMiddleMonsters()){
                        if (1==Utils.randomMonsterChop(0,2)){
                            item.UseSingleFunctionWeapon(item.getCurrentWeapon(), this.getPlayer());
                        }else {

                        }
                    }
                } else {
                    ui.displyErrorCmdMsg();
                }

            }
            if (currentCave.getId().equals("03")) {

                if (cmddLineItem[0].equals("bye")) {
                    ui.displayBye();
                    System.exit(0);
                } else if (cmddLineItem[0].equals("help")) {
                    ui.displayHelpMsg();
                } else if (cmddLineItem[0].equals("go")) {
                    goCave(cmddLineItem[1]);
                } else if (cmddLineItem[0].equals("attack")) {

                } else {
                    ui.displyErrorCmdMsg();
                }
            }
            if (currentCave.getId().equals("04")) {

                if (cmddLineItem[0].equals("bye")) {
                    ui.displayBye();
                    System.exit(0);
                } else if (cmddLineItem[0].equals("help")) {
                    ui.displayHelpMsg();
                } else if (cmddLineItem[0].equals("go")) {
                    goCave(cmddLineItem[1]);
                } else if (cmddLineItem[0].equals("attack")) {

                } else if (cmddLineItem[0].equals("cure")) {

                } else {
                    ui.displyErrorCmdMsg();
                }
            }
            if (currentCave.getId().equals("05")) {

                if (cmddLineItem[0].equals("bye")) {
                    ui.displayBye();
                    System.exit(0);
                } else if (cmddLineItem[0].equals("help")) {
                    ui.displayHelpMsg();
                } else if (cmddLineItem[0].equals("go")) {
                    goCave(cmddLineItem[1]);
                } else if (cmddLineItem[0].equals("cure")) {

                } else {
                    ui.displyErrorCmdMsg();
                }

            }
            if (currentCave.getId().equals("06")) {

                if (cmddLineItem[0].equals("bye")) {
                    ui.displayBye();
                    System.exit(0);
                } else if (cmddLineItem[0].equals("help")) {
                    ui.displayHelpMsg();
                } else if (cmddLineItem[0].equals("go")) {
                    goCave(cmddLineItem[1]);
                } else {
                    ui.displyErrorCmdMsg();
                }
            }
        }


    }


    public PersonPlayer getPlayer() {
        return player;
    }

    public void setPlayer(PersonPlayer player) {
        this.player = player;
    }

    public Cave getCurrentCave() {
        return currentCave;
    }

    public void setCurrentCave(Cave currentCave) {
        this.currentCave = currentCave;
    }

    public CaveSet getCaveSet() {
        return caveSet;
    }

    public void setCaveSet(CaveSet caveSet) {
        this.caveSet = caveSet;
    }

    public EntranceMonsterSet getEntranceMonsterSet() {
        return entranceMonsterSet;
    }

    public void setEntranceMonsterSet(EntranceMonsterSet entranceMonsterSet) {
        this.entranceMonsterSet = entranceMonsterSet;
    }

    public MiddleCaveMonsterSet getMiddleCaveMonsterSet() {
        return middleCaveMonsterSet;
    }

    public void setMiddleCaveMonsterSet(MiddleCaveMonsterSet middleCaveMonsterSet) {
        this.middleCaveMonsterSet = middleCaveMonsterSet;
    }

    public RattanCaveCreatureSet getRattanCaveMonsterSet() {
        return rattanCaveMonsterSet;
    }

    public void setRattanCaveMonsterSet(RattanCaveCreatureSet rattanCaveMonsterSet) {
        this.rattanCaveMonsterSet = rattanCaveMonsterSet;
    }

    public WolfCaveMonsterSet getWolfCaveMonsterSet() {
        return wolfCaveMonsterSet;
    }

    public void setWolfCaveMonsterSet(WolfCaveMonsterSet wolfCaveMonsterSet) {
        this.wolfCaveMonsterSet = wolfCaveMonsterSet;
    }
}
